package me.zhengjie.modules.zhishiku.rest;

import me.zhengjie.aop.log.Log;
import me.zhengjie.modules.zhishiku.domain.TZhishiku;
import me.zhengjie.modules.zhishiku.service.TZhishikuService;
import me.zhengjie.modules.zhishiku.service.dto.TZhishikuQueryCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
* @author jie
* @date 2020-08-03
*/
@RestController
@RequestMapping("api")
public class TZhishikuController {

    @Autowired
    private TZhishikuService tZhishikuService;

    @Log("查询TZhishiku")
    @GetMapping(value = "/tZhishiku")
    public ResponseEntity getTZhishikus(TZhishikuQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity(tZhishikuService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @Log("新增TZhishiku")
    @PostMapping(value = "/tZhishiku")
    public ResponseEntity create(@Validated @RequestBody TZhishiku resources){
        return new ResponseEntity(tZhishikuService.create(resources),HttpStatus.CREATED);
    }

    @Log("修改TZhishiku")
    @PutMapping(value = "/tZhishiku")
    public ResponseEntity update(@Validated @RequestBody TZhishiku resources){
        tZhishikuService.update(resources);
        return new ResponseEntity(HttpStatus.NO_CONTENT);
    }

    @Log("删除TZhishiku")
    @DeleteMapping(value = "/tZhishiku/{id}")
    public ResponseEntity delete(@PathVariable Integer id){
        tZhishikuService.delete(id);
        return new ResponseEntity(HttpStatus.OK);
    }
}